<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cesium添加arcgisserver4490tile</title>
    <link rel="stylesheet" href="http://192.168.1.90:8088/lib/cesium-1.90-4490/Cesium/Widgets/widgets.css" type="text/css">
    <script src="http://192.168.1.90:8088/lib/cesium-1.90-4490/Cesium/Cesium.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #cesiumContainer {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
<div id="cesiumContainer"></div>
<script>

    //Cesium token
    let cesium_tk = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWRlMmQ1Ni1iNGMxLTRhY2YtYmExYi1jNjYyNTUxNDhjYzgiLCJpZCI6MjMwODAsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyIsInByIl0sImlhdCI6MTU4OTE4NzE1NH0.QrUVmI13wKIqFwmnsGSR6aMr8FEtbO7jsTA0mqnvbdM";

    let type = 'img'
    Cesium.Ion.defaultAccessToken = cesium_tk;
    window.viewer = new Cesium.Viewer('cesiumContainer', {
        // imageryProvider: layer,
        geocoder: false,
        homeButton: false,
        sceneModePicker: false,
        baseLayerPicker: false,
        navigationHelpButton: false,
        animation: false,
        timeline: false,
        fullscreenButton: false,
        vrButton: false,
        infoBox: false,
        selectionIndicator: false
        // shouldAnimate: true
    });

    // this.addDem()
    // window.viewer.scene.globe.depthTestAgainstTerrain=true
    window.viewer.scene.screenSpaceCameraController.enableCollisionDetection = false;
    window.viewer._cesiumWidget._creditContainer.style.display = "none";// 隐藏 LOGO 版权

    let imageryLayers = window.viewer.imageryLayers;
    let imageryProvider = new Cesium.ArcGisMapServerImageryProvider({
        url : "https://jiangsu.tianditu.gov.cn/mapjs2/rest/services/MapJS/js_yxdt_latest/MapServer",
    })
    let testLayer = imageryLayers.addImageryProvider(imageryProvider);
    testLayer.show = true


    function  flyToMapByExtent() {
        window.viewer.camera.setView({
            destination : Cesium.Cartesian3.fromDegrees(120.46292388403401, 32.53487644346701, 130000.0),//摄像机在 WGS84（世界）坐标中的最终位置，或从自上而下视图可见的矩形
            orientation : {//包含方向和向上属性或航向、俯仰和滚动属性的对象
                heading : Cesium.Math.toRadians(0), // （方向）east, default value is 0.0 (north)此处可根据个人需求实际取值
                pitch : Cesium.Math.toRadians(-90),    // （视角）default value (looking down)此处可根据个人需求实际取值
                roll : 0.0                             //（倾斜角度） default value此处可根据个人需求实际取值
            }
        });
    }

    flyToMapByExtent()

    // 定义最小高度，对应于2D地图的zoom level 19。
    // 注意：这个值不是精确对应，需要根据实际需求调整。
    var minCameraHeight = 100; // 以米为单位

    // 监听摄像机的变化
    viewer.scene.camera.moveEnd.addEventListener(function() {
        var cameraHeight = viewer.camera.positionCartographic.height;
        if (cameraHeight < minCameraHeight) {
            viewer.camera.flyTo({
                destination: Cesium.Cartesian3.fromDegrees(viewer.camera.positionCartographic.longitude * (180 / Math.PI), viewer.camera.positionCartographic.latitude * (180 / Math.PI), minCameraHeight),
                orientation: {
                    heading: viewer.camera.heading,
                    pitch: viewer.camera.pitch,
                    roll: viewer.camera.roll
                },
                duration: 0 // 瞬间跳转，没有动画效果
            });
        }
    });
</script>


</body>
</html>